#include<bits/stdc++.h>
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x*f;
}
#define int long long 
#define It set<int>::iterator
const int N=5e5+4;
int q;
namespace bl{
    set<int> s;
    int solve(){
        if(!s.size()) return 0;
        int ans=0,s1=0,s2=0,li=0;
        for(auto it=s.begin(),ti=prev(s.end());it!=s.end();it++,ti--){
            s1+=*it,s2+=*ti,li=max(li,s1);
            ans+=max(s2-li,0ll),li=max(li,s2);
        }
        return ans;
    }
    void main(){
        while(q--){
            int x=read();
            if(s.find(x)==s.end()) s.insert(x);
            else s.erase(x);
            cout<<solve()<<"\n";
        }
    }
}
signed main(){
    freopen("kte.in","r",stdin);
    freopen("kte.out","w",stdout);
    q=read();
    bl::main();
	return 0;
}